package com.zmx.job.admin.core.nodedistribute;

import com.zmx.job.admin.core.nodedistribute.routestrategy.BestPerformance;
import com.zmx.job.admin.enums.RoutStrategyEnum;
import com.zmx.job.admin.core.nodedistribute.routestrategy.Random;
import com.zmx.job.admin.core.nodedistribute.routestrategy.RoundRobin;
import com.zmx.job.admin.core.nodedistribute.routestrategy.RoundRobinWeight;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description: 节点分发帮组类
 * @ClassName: NodeDistributeHelper
 * @Author zhaomxr
 * @Date 2021-12-22 15:25
 */
@Slf4j
public class NodeDistributeHelper {

    public static String getNode(RoutStrategyEnum strategyEnum) {

        //请求地址（具体分发实例）
        String node = "";
        switch (strategyEnum) {
            case RANDOM:
                node = Random.get();
                break;
            case POLLING:
                node = RoundRobin.get();
                break;
            case POLLINGWEIGHT:
                node = RoundRobinWeight.get();
                break;
            case BESTPERFORMANCE:
                node = BestPerformance.get();
                break;
            default:
                //默认使用随机算法
                node = Random.get();
                break;
        }

        log.info("节点分发策略：{} 选举结果：{}", strategyEnum.getDesc(), node);
        return node;
    }
}
